home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: new-news.sprintlink.net!eskimo!news
- From: mag@eskimo.com (mAg)
- Subject: Re: #include "" for large programs.
- X-Nntp-Posting-Host: tia1.eskimo.com
- Message-ID: <Dpw2FI.KJt@eskimo.com>
- Sender: news@eskimo.com (News User Id)
- Organization: *.*
- X-Newsreader: WinVN 0.93.10
- References: <Pine.SUN.3.92.960411195730.24973A-100000@suntan>
- Date: Mon, 15 Apr 1996 05:40:28 GMT
-
- In article <Pine.SUN.3.92.960411195730.24973A-100000@suntan> (Thu, 11 Apr 1996 20:05:59
- -0400), cdiaz@eng.usf.edu says :
- >
- >Hello!
- > I've been writing short two part programs using the #include "filename"
- >preprocessor.
- > I call one file main.c and the other part2.c, for which there is a
- >prototype header file part2.h.
- > All works well when I compile the programs, except when part2.h has
- >#define constants (I've been advised by my professor to use #define for
- >constants over 'const type var_name'). My compiler returns a fatal error
- >reporting that the symbol in the #define is not defined.
- > For example if #define EQUAL 0 is part of part2.h, I'm told that the
- >symbol EQUAL is not defined. But if I put the #define inside main.c, I'm
- >told that I've defined EQUAL TWICE, once in part2.h and again within
- >main. The book we're using in class is not helping at all in this subject,
- >and I cannot figure out why everything else is recognized, except #define
- >constants. Can anyone here help? If the answer to this is in the FAQ, just
- >tell me where to download it from. Thanks!
- >
- >-Carlos E. Diaz
- >
- >
-
- The constants should be declared only in one file.
-
- Here is an example of how it should be done. Let us assume that we have a constant
- MAX_LEN = 80.
-
-
-
- /* myprog.h */
- #define MAX_LEN 80
-
- /* === */
-
-
-
- /* main.c */
- #include "myprog.h"
-
- /* use MAX_LEN */
-
- /* === */
-
-
-
- /* subpart1.c */
-
- /* use MAX_LEN */
-
- /* === */
-
- --
- /* --------------------------------------------------------
- MAG@ESKIMO.COM
- http://www.eskimo.com/~mag/index.html
- ***********************************************************
- To understand recursion one must first understand recursion
- ***********************************************************
- -------------------------------------------------------- */
-
-